#!/usr/bin/env python
#coding=utf-8
import os
import socket
ip="127.0.0.1"
port=(80,3306)
m={}
#添加示例，以字典的方式进行添加
server_port={"nginx":80,"mysql":3306,"tomcat":8080,"socket":11000}
def f(ip,port,server_name=None):
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    try:
        s.connect((ip,int(port)))
        s.shutdown(2)
        m["port_%s_%s" %(server_name,port)]=1
        return m
    except:
        m["port_%s_%s" %(server_name,port)]=0
        return m


for n , p in server_port.items():
    port_zu = f(ip,p,n)

